using System;
using System.Collections.Generic;
using System.Text;

namespace OpenSocial.Net.People
{
	/// <summary>
	/// Provider of People data.
	/// Ref: http://code.google.com/apis/opensocial/docs/gdata/people/reference.html
	/// </summary>
	public class PeopleProvider : ProviderBase
	{
		#region Constructor

		/// <summary>
		/// Initializes a new instance of the <see cref="PeopleProvider"/> class.
		/// </summary>
		/// <param name="domain">The domain to access People data from.</param>
		public PeopleProvider(string domain) 
			: base(domain)
		{

		}

		/// <summary>
		/// Initializes a new instance of the <see cref="PeopleProvider"/> class.
		/// </summary>
		/// <param name="authToken">The authorization token.</param>
		/// <param name="domain">The domain to access People data from.</param>
		public PeopleProvider(string domain, string authToken)
			: base(domain, authToken)
		{

		}

		#endregion Constructor

		#region Friend Members

		public FriendList GetFriendList(ulong userID)
		{
			string atom = GetFriendAtomFeed(userID);
			PeopleBuilder builder = new PeopleBuilder();
			FriendList flist = builder.BuildFriendList(atom);
			return flist;
		}

		protected string GetFriendAtomFeed(ulong userID)
		{
			//Format: http://domain/feeds/people/UserID/friends
			string atomUrl = string.Format(@"{0}/feeds/people/{1}/friends", Domain, userID);
			System.Diagnostics.Trace.WriteLine(atomUrl, "GetFriendAtomFeed");
			string atom = base.GetOpenSocialData(atomUrl, AuthToken);
			return atom;
		}

		#endregion Friend Members

		#region Person Members

		public Person GetPerson(ulong userID)
		{
			string atom = GetPersonAtomFeed(userID);
			PeopleBuilder builder = new PeopleBuilder();
			Person person = builder.BuildPerson(atom);
			return person;
		}

		protected string GetPersonAtomFeed(ulong userID)
		{
			//Format: http://domain/feeds/people/UserID
			string atomUrl = string.Format(@"{0}/feeds/people/{1}", Domain, userID);
			System.Diagnostics.Trace.WriteLine(atomUrl, "GetPersonAtomFeed");
			string atom = base.GetOpenSocialData(atomUrl, AuthToken);
			return atom;
		}

		#endregion Person Members
	}
}
